package com.kitty.spring.annotationdriven.typefilter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @Description
 * @Author SHEN
 * @Date 2020/12/6
 */
public class MyTypeFilter implements TypeFilter {


    /**
     * 确定此过滤器是否与给定元数据描述的类匹配。
     * @param metadataReader 当前扫描类的信息
     * @param metadataReaderFactory 用于获取其他类（​例如超类和接口）的信息的工厂
     */
    @Override
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //当前扫描类的注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        //当前扫描类的类信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();

        //获取当前扫描类的资源信息
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println("className = " + className);
        return false;
    }
}
